using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
using ZoneFiveSoftware.Common.Visuals.Fitness;
using ZoneFiveSoftware.Common.Data.Fitness;
using ZoneFiveSoftware.Common.Data;
using SportTracksPluginFramework;
using DistributionPlugin.View;
using DistributionPlugin.Controller;

#if DEBUG
using STCommon.NUnit;
#endif

namespace DistributionPlugin
{
    public class PluginMain : STFrameworkEntryPoint, IPlugin
    {
        public PluginMain() : base(GUIDs.PluginMain)
        {
            DistributionFrameworkExtension.DistributionFrameworkExtension.Initialize(this);

#if DEBUG
            String testAssemblyLocation = typeof(PluginMain).Assembly.Location;
            testAssemblyLocation = testAssemblyLocation.Substring(0, testAssemblyLocation.LastIndexOf('\\'));
            testAssemblyLocation += "\\DistributionUnitTests.dll";

            NUnitTestManager.Instance.RegisterTestAssembly(testAssemblyLocation);
#endif
        }

#region STFrameworkEntryPoint Members

        public override string Name
        {
            get { return PluginView.GetLocalizedString("DistributionPluginText"); }
        }

        public override void ReadOptions(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, XmlElement pluginNode)
        {
            foreach (XmlNode currentChild in pluginNode.ChildNodes)
            {
                switch(currentChild.Name)
                {
                    case DailyActivityOptionsXmlNodeName:
                    {
                        ActivityDetailsOptions.DailyActivityInstance.LoadFromXml(currentChild);
                        break;
                    }
                    case ReportsActivityOptionsXmlNodeName:
                    {
                        ActivityDetailsOptions.ReportsActivityInstance.LoadFromXml(currentChild);
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
        }

        public override void WriteOptions(XmlDocument xmlDoc, XmlElement pluginNode)
        {
            ActivityDetailsOptions.DailyActivityInstance.SaveToXml(xmlDoc, pluginNode, DailyActivityOptionsXmlNodeName);
            ActivityDetailsOptions.ReportsActivityInstance.SaveToXml(xmlDoc, pluginNode, ReportsActivityOptionsXmlNodeName);
        }
    
        protected override void Initialize()
        {
        }
    
        public override string DonationLink
        {
            get
            {
                return "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K47V9KLLT7338";
            }
        }

        public override Control DonationReminderControl
        {
            get
            {
                return new DistributionReminderControl();
            }
        }

#endregion

        private const String DailyActivityOptionsXmlNodeName = "DailyActivityOptions";
        private const String ReportsActivityOptionsXmlNodeName = "ReportsActivityOptions";
    }
}
